#include <iostream>
#include <limits.h>

struct TreeNode
{
    int val;
    TreeNode* left;
    TreeNode* right;
};

class Solution {
public:
    // 该节点，该节点的取值范围
    bool _isValidBST(TreeNode* root, long long lower, long long upper)
    {
        if(root == nullptr)
            return true;

        if(root->val <= lower || root->val >= upper)
            return false;

        return _isValidBST(root->left, lower, root->val) && _isValidBST(root->right, root->val, upper);
    }

    bool isValidBST(TreeNode* root) {
        return _isValidBST(root, LONG_MIN, LONG_MAX);
    }
};

//添加区间遍历，通过不断递归，改变区间的范围